home *** CD-ROM | disk | FTP | other *** search
- //***************************************************************************
- // OATH :: Object-oriented Abstract Type Hierarchy
- //***************************************************************************
- //
- // Copyright (C) 1991, 1990 Texas Instruments Incorporated
- // Permission is granted to any individual or institution
- // to use, copy, modify, and distribute this software,
- // provided that this complete copyright and permission notice
- // is maintained, intact, in all copies and supporting documentation.
- //
- // Texas Instruments Incorporated provides this software "as is"
- // without express or implied warranty.
- //
- //***************************************************************************
- // string (stringA, stringG)
- // stringPos (stringPosA, stringPosG)
- //
- // History:
- // 06/91 Brian M Kennedy New macros & format; remove printDiagnostic
- // 10/90 Brian M Kennedy Major Rewrite
- // 02/90 Brian M Kennedy Original
- //
- //***************************************************************************
-
- #include "copyright.h"
-
- #include <oath/string.h>
-
- #include <stdlib.h>
-
- #include <math.h> /* shouldn't be needed, but abs not in stdlib! */
-
- /////////////////////////////////////////////////////////////////////////////
- // string Outlines
-
- OUTLINES(string, list)
-
- int stringG::
- hash (const char * C)
- {int H = 0;
- while(*C)
- {H = (H << 2) + *C;
- C++;
- }
- return abs(H);
- }
-
- int stringG::
- hash (const stringPosG* Start, const stringPosG* Beyond)
- {int H = 0;
- stringPosA P = (stringPosA&)Start->makeCopy(0);
- while(P() && !P.guts()->isEqual(Beyond))
- {H = (H << 2) + (*P).value();
- ++P;
- }
- assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
- return abs(H);
- }
-
- int stringG::
- hashLower (const char * C)
- {int H = 0;
- while(*C)
- {H = (H << 2) + tolower(*C);
- C++;
- }
- return abs(H);
- }
-
- int stringG::
- hashLower (const stringPosG* Start, const stringPosG* Beyond)
- {int H = 0;
- stringPosA P = (stringPosA&)Start->makeCopy(0);
- while(P() && !P.guts()->isEqual(Beyond))
- {H = (H << 2) + tolower((*P).value());
- ++P;
- }
- assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
- return abs(H);
- }
-
- int stringG::
- hashUpper (const char * C)
- {int H = 0;
- while(*C)
- {H = (H << 2) + toupper(*C);
- C++;
- }
- return abs(H);
- }
-
-
- int stringG::
- hashUpper (const stringPosG* Start, const stringPosG* Beyond)
- {int H = 0;
- stringPosA P = (stringPosA&)Start->makeCopy(0);
- while(P() && !P.guts()->isEqual(Beyond))
- {H = (H << 2) + toupper((*P).value());
- ++P;
- }
- assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
- return abs(H);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // stringPos Outlines
-
- OUTLINES(stringPos, listPos)
-
- //***************************************************************************
-